﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MODULE_NHAPXUAT
{
    public partial class frm_inphieukiemdinh : Form
    {
        nhapxuatDataContext context = cls_nhapxuat.getcontext();
        private string sophieu;
        public string _sophieu
        {
            get 
            { 
                return sophieu; 
            }
            set 
            { 
                sophieu = value; 
            }
        }
        public frm_inphieukiemdinh()
        {
            InitializeComponent();
        }

        private void frm_inphieukiemdinh_Load(object sender, EventArgs e)
        {
            IEnumerable<DM_CongTy> congtys = from c in context.DM_CongTies select c;
            
            this.cbcongty.DataSource = congtys;
            this.cbcongty.ValueMember = "macongty";
            this.cbcongty.DisplayMember = "tencongty";
        }

        private void btOK_Click(object sender, EventArgs e)
        {
            try
            {
               String macongty=this.cbcongty.SelectedValue.ToString();

                IEnumerable<kcs> lst = from c in context.kcs where c.sophieu.Equals(sophieu) select c;



                MODULE_TIENICH.cls_report objReport = new MODULE_TIENICH.cls_report();
                MODULE_TIENICH.cls_tienich cls = new MODULE_TIENICH.cls_tienich();
                //DataTable dt = cls.IEnumerabletoDataTable(lst);
                Cursor.Current = Cursors.WaitCursor;
                if (macongty == constant.DAIVIET)
                {
                    objReport.Load_Report(Application.StartupPath + "\\reports\\kcs_daiviet.rpt", lst);
                   
                    //objReport.Load_SubReport("Sub_BienBanNhap_VTNPL_BTP", objCtrl.LoadPrint_BienBanNhap_L)
                }
                if (macongty == constant.VANXUAN)
                {
                    objReport.Load_Report(Application.StartupPath + "\\reports\\kcs_vanxuan.rpt", lst);
                }

                DateTime d = context.p_getdate().ElementAt(0).serverdatetime;

                if (d.Day < 10)
                {
                    objReport.Formulas_Report("ngay", "'0" + d.Day.ToString() + "'");
                }
                else
                {
                    objReport.Formulas_Report("ngay", "'" + d.Day.ToString() + "'");
                }
                if (d.Month < 10)
                {
                    objReport.Formulas_Report("thang", "'0" + d.Month.ToString() + "'");
                }
                else
                {
                    objReport.Formulas_Report("thang", "'" + d.Month.ToString() + "'");
                }

                objReport.Formulas_Report("nam", "'" + d.Year.ToString() + "'");


                objReport.Open_Report();
                Cursor.Current = Cursors.Default;
                //objCtrl = Nothing
                //objReport = null;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void btCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
